home *** CD-ROM | disk | FTP | other *** search
/ Enter 2005 October / enter-2005-10.iso / files / jedit42install.exe / {app} / jedit.jar / bsh / commands / fontMenu.bsh < prev    next >
Encoding:
Text File  |  2003-12-27  |  1.9 KB  |  77 lines

  1. /**
  2.  * Creates a font menu for use with the workspace and workspace editors
  3.  *
  4.  * @return a font menu
  5.  *
  6.  * @author Daniel Leuck
  7.  */
  8. fontMenu(component) {
  9.     if ( bsh.system.desktop == void ) {
  10.         print("fontMenu() only works with the bsh desktop...");
  11.         return;
  12.     }
  13.     
  14.     JMenu fontMenu = new JMenu("Font");
  15.     
  16.     sizeListener() {
  17.         actionPerformed(ae) {
  18.             setFont(component, Integer.parseInt(ae.actionCommand));
  19.         }
  20.     
  21.         return this;    
  22.     }
  23.     this.sizeListener=sizeListener();
  24.     
  25.     
  26.     this.boldMenuItem = new JCheckBoxMenuItem("Bold");
  27.     this.italicMenuItem = new JCheckBoxMenuItem("Italic");
  28.     
  29.     styleListener() {
  30.         actionPerformed(ae) {
  31.             setFont(component, null, ((boldMenuItem.selected) ? Font.BOLD : 0) |
  32.                 ((italicMenuItem.selected) ? Font.ITALIC : 0), -1);
  33.         }
  34.     
  35.         return this;    
  36.     }
  37.     this.styleListener=styleListener();
  38.     
  39.     familyListener() {
  40.         actionPerformed(ae) {
  41.             setFont(component, ae.actionCommand, -1, -1);
  42.         }
  43.     
  44.         return this;    
  45.     }
  46.     this.familyListener=familyListener();    
  47.     
  48.     JMenu sizeMenu = new JMenu("Size");
  49.     for(int i:new int[] {9,10,12,14,16,20,24})
  50.         sizeMenu.add(new JMenuItem(""+i)).addActionListener(sizeListener);
  51.     fontMenu.add(sizeMenu);
  52.     
  53.     JMenu styleMenu = new JMenu("Style");
  54.     //styleMenu.add(new JMenuItem("Plain")).addActionListener(this);
  55.     styleMenu.add(boldMenuItem).addActionListener(styleListener);
  56.     styleMenu.add(italicMenuItem).addActionListener(styleListener);
  57.     fontMenu.add(styleMenu);
  58.     
  59.     fontMenu.addSeparator();
  60.     
  61.     for(var s:new String[] {"SansSerif","Monospaced","Serif","LucidaSans"})
  62.         fontMenu.add(this.mi=new JMenuItem(s)).addActionListener(familyListener);
  63.     
  64.     fontMenu.addSeparator();
  65.     
  66.     actionPerformed(ae) {
  67.         String family = (String)JOptionPane.showInputDialog(component,
  68.             "Select a font", "Fonts", JOptionPane.QUESTION_MESSAGE,
  69.                 null, bsh.system.fonts, component.font.family);
  70.         setFont(component, family, -1, -1);
  71.     }
  72.     
  73.     fontMenu.add(new JMenuItem("More...")).addActionListener(this);
  74.     
  75.     return fontMenu;
  76. }
  77.